{template 'common/header-storex'}
<div class="wn-main wn-main--without">
	<div class="wn-main__head"><a href="{php echo $this->createWebUrl('shop_order',array('op' => 'list', 'storeid' => $storeid));}">订单管理</a> / 订单编辑</div>
	<div class="wn-main__content">
		{if !empty($logs)}
			<ul class="nav nav-pills nav-justified step step-round">
				{loop $logs $log}
					<li class="active">
						<a>{$log['time']}--{$log['msg']}</a>
					</li>
				{/loop}
			</ul>
		{/if}
		{if !empty($item['roomid'])}
		<table class="table table-bordered wn-table text-center">
			<tr>
				<th class="text-center">商品</th>
				<th class="text-center">数量</th>
				<th class="text-center">单价</th>
				<th class="text-center">小计</th>
			</tr>
			<tr>
				<td>{$room['title']}</td>
				<td>{$item['nums']}</td>
				<td>
				{if !empty($good_info) && !empty($good_info['price_list'])}
				<button type="button" data-toggle="modal" data-target="#price-modal" class="btn but btn-default">价格明细</button>
				{else}
				{$item['cprice']}
				{/if}
				</td>
				<td>{$item['sum_price']}</td>
			</tr>
		</table>
		{else}
		<table class="table table-hover wn-table table-bordered">
			<thead class="navbar-inner">
				<tr>
					<th class="text-center">商品</th>
					<th class="text-center">数量</th>
					<th class="text-center">单价</th>
					<th class="text-center">规格</th>
					<th class="text-center">套餐</th>
				</tr>
			</thead>
			<tbody>
				{loop $item['cart'] $good}
				<tr>
					<td>{$good['good']['title']}</td>
					<td>{$good['good']['buynums']}</td>
					<td>{$good['good']['cprice']}</td>
					{if $good['buyinfo']['2'] == 1}
					<td>{php echo implode(' ', $good['good']['spec_info']['goods_val'])}
					</td>
					<td>不是套餐</td>
					{elseif $good['buyinfo']['2'] == 2}
					<td>无规格</td>
					<td>不是套餐</td>
					{elseif $good['buyinfo']['2'] == 3}
					<td>无规格</td>
					<td>
					{if !empty($good['package'])}
					套餐商品:{$good['package']['good']} <br>
					套餐价格:{$good['package']['price']} <br>
					套餐运费:{$good['package']['express']} <br>
					{/if}
					</td>
					{/if}
				</tr>
				{/loop}
			</tbody>
		</table>
		{/if}
		<div class="wn-order">
			<div class="wn-order__detail form form-horizontal">
				<h4>订单信息</h4>
				<div class="form-group">
					<label class="col-sm-4 control-label">订单编号</label>
					<div class="col-sm-8 form-control-static">
						{$item['ordersn']}
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-4 control-label">商户订单号</label>
					<div class="col-sm-8 form-control-static">
						{if !empty($item['uniontid'])}{$item['uniontid']}{else}暂无{/if}
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-4 control-label">订单类型</label>
					<div class="col-sm-8 form-control-static">
						{if $store_type == STORE_TYPE_HOTEL}
						酒店订单{if isset($room['is_house']) && $room['is_house'] == 1} / 房型订单{else} / 普通订单{/if}
						{else}
						普通订单
						{/if}
					</div>
				</div>
				{if !empty($good_info) && $good_info['is_house'] == 1}
				<div class="form-group">
					<label class="col-sm-4 control-label">到店时间</label>
					<div class="col-sm-8 form-control-static">
						{php echo date('Y-m-d', $item['btime']);}
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-4 control-label">离店时间</label>
					<div class="col-sm-8 form-control-static">
						{php echo date('Y-m-d', $item['etime']);}
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-4 control-label">住几晚</label>
					<div class="col-sm-8 form-control-static">
						{$item['day']}
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-4 control-label">房量/房态</label>
					<div class="col-sm-8 form-control-static">
						<select multiple="true" name="room_list" id="room_list" style="height:100px" class='form-control'>
							{loop $date_array $row}
							<option value="{$row['month']}-{$row['day']}|{$list[$row['time']]['status']}|{$list[$row['time']]['num']}">
								{$row['month']}-{$row['day']} --
								{if $list[$row['time']]['status'] == 1 && ($list[$row['time']]['num'] > 0 || $list[$row['time']]['num'] == '不限')}
								有房
								--
								{$list[$row['time']]['num']}
								{else}
								无房
								{/if}
							</option>
							{/loop}
						</select>
					</div>
				</div>
				{/if}
				<div class="form-group">
					<label class="col-sm-4 control-label">付款方式</label>
					<div class="col-sm-8 form-control-static">{$item['paytype_text']}</div>
				</div>
				<div class="form-group">
					<label class="col-sm-4 control-label">订单时间</label>
					<div class="col-sm-8 form-control-static">
						{php echo date('Y-m-d H:i:s', $item['time']);}
					</div>
				</div>
				<hr />
				<h4>用户信息</h4>
				<div class="form-group">
					<label class="col-sm-4 control-label">用户类型</label>
					<div class="col-sm-8 form-control-static">
						{if $member_info['isauto'] == 1}微信用户{else}会员用户{/if}
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-4 control-label">联系人</label>
					<div class="col-sm-8 form-control-static">
						{$item['contact_name']}
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-4 control-label">手机号</label>
					<div class="col-sm-8 form-control-static">
						{$item['mobile']}
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-4 control-label">买家留言</label>
					<div class="col-sm-8 form-control-static">
						{$item['remark']}
					</div>
				</div>
			</div>
			<div class="wn-order__action">
				<form action="" class="form-horizontal form wn-form" method="post" enctype="multipart/form-data" onsubmit="">
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">备注</label>
						<div class="col-sm-9 col-xs-12 form-control-static">
							<textarea style="height:100px;" class="form-control richtext-clone" name="msg" cols="70" id="reply-add-text">{$item['msg']}</textarea>
						</div>
					</div>
					<div class="form-group">
						<input type="hidden" name="id" value="{$item['id']}">
						<input type="hidden" name="op" value="edit_msg">
						<input type="hidden" name="storeid" value="{$storeid}" />
						<input type="submit" name="submit" value="提交" class="btn btn-primary" />
						<input type="hidden" name="token" value="{$_W['token']}" />
					</div>
				</form>
				
				<form action="" class="form-horizontal form wn-form" method="post" enctype="multipart/form-data">
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">支付状态</label>
						<div class="col-sm-9 col-xs-12 form-control-static">
							{if $item['paystatus'] == 0}
								未支付
							{elseif $item['paystatus'] == 1}
								已支付
								{if $refund_logs['status'] == REFUND_STATUS_SUCCESS}
								,已退款成功
								{/if}
							{else}
								其他
							{/if}
						</div>
					</div>
					{if (empty($good_info) || $good_info['is_house'] != 2) && $item['status'] != -1 && $item['status'] != 2 && $item['status'] != 3}
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">商品状态</label>
						<div class="col-sm-9 col-xs-12 form-control-static">
							{if !empty($good_info) && $good_info['is_house'] == 1}
								{if empty($item['goods_status']) || $item['goods_status'] == 4}
									待入住
								{elseif $item['goods_status'] == 5}
									已入住
								{/if}
							{/if}
						</div>
					</div>
					{/if}
					{if !empty($actions) && is_array($actions)}
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">操作</label>
						<div class="col-sm-9 col-xs-12 form-control-static">
						{loop $actions $ac $text}
							<button type="button" data-toggle="modal" data-target="#orderConfirm" class="btn but btn-default" value="{$ac}" >{$text}</button>
						{/loop}
						</div>
					</div>
					{/if}
					{if $is_house == 1 && $item['status'] != -1 && $item['status'] != 2}
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">分配房间号</label>
						<div class="col-sm-2 col-xs-12 form-control-static">
							<div>
								{$roomnumber}
							</div>
						</div>
						<div class="col-sm-6 col-xs-12">
							<button type="button" data-toggle="modal" data-target="#room-modal" class="btn but btn-default">分配房间</button>
						</div>
					</div>
					{/if}
				</form>
			</div>
		</div>
		{if !empty($logs)}
		<div class="wn-order">
			<div class="col-xs-12">
			<h4>订单操作记录</h4>
				{loop $logs $log}
				<div>
					<span>
					{$log['time']} {$log['clerk_type']} {$log['type']} {$log['msg']}
					</span>
				</div>
				<br>
				{/loop}
			</div>
		</div>
		{/if}
	</div>
</div>

<div id="price-modal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
	<div class="modal-dialog modal-dialog-default modal-lg">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h3>
					<ul role="tablist" class="nav nav-pills" style="font-size:14px; margin-top:-20px;">
						<li role="presentation" class="basic">
							<a data-toggle="tab" data-type="basic" role="tab" aria-controls="baisc" href="#basic">价格明细</a>
						</li>
					</ul>
				</h3>
			</div>
			<div class="modal-body modules-content">
				<div class="tab-content">
					<table class="table table-bordered wn-table text-center">
					<tr>
						<th class="text-center">日期</th>
						<th class="text-center">原价</th>
						<th class="text-center">现价</th>
					</tr>
					{loop $good_info['price_list'] $price_info}
						<tr>
							<td>{$price_info['date']}</td>
							<td>{$price_info['oprice']}</td>
							<td>{$price_info['cprice']}</td>
						</tr>
					{/loop}
					</table>
				</div>
			</div>
		</div>
	</div>
</div>

<div id="room-modal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
	<div class="modal-dialog modal-dialog-default modal-lg">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h3>
					<ul role="tablist" class="nav nav-pills" style="font-size:14px; margin-top:-20px;">
						<li role="presentation" class="basic">
							<a data-toggle="tab" data-type="basic" role="tab" aria-controls="baisc" href="#basic">选择房间</a>
						</li>
					</ul>
				</h3>
			</div>
			<div class="modal-body modules-content">
				<div class="tab-content">
					{if !empty($room_list)}
					{loop $room_list $room}
						<input class='room-input' type='checkbox' name="room[]" value="{$room['id']}" {if !empty($food['foods_set']) && in_array($title, $food['foods_set'])} checked {/if}/>
						房间 {$room['roomnumber']}
					{/loop}
					{else}
					<div class="text-center">未设置房间</div>
					{/if}
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				<a class="btn btn-primary order_set_room">提交</a>
			</div>
		</div>
	</div>
</div>

<div class="modal fade" id="orderConfirm" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
	<div class="modal-dialog" role="document">
		<form action="" class="form-horizontal form wn-form" method="post" enctype="multipart/form-data" onsubmit="return formcheck();">
		<div class="modal-content">
			<div class="modal-header">
				确认操作
			</div>
			<div class="modal-body">
				确认此操作？
				<input type="hidden" name="id" value="{$item['id']}">
				<input type="hidden" name="storeid" value="{$storeid}" />
				<input type="hidden" name="token" value="{$_W['token']}" />
				<input type="hidden" id="action" name="action" value="{$ac}">
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				<a class="btn btn-primary js-submit">提交</a>
			</div>
		</div>
		</form>
	</div>
</div>
<script type="text/javascript">
	var storeid = {$storeid};
	var id = {$item['id']};
	var roomid = {$item['roomid']};
	var num = {$item['nums']};
	require(['bootstrap'],function($) {
		$('#orderConfirm').on('show.bs.modal', function(e) {
			$('#action').val(e.relatedTarget.value);
		});
		$('.js-submit').click(function() {
			var action = $('#action').val();
			$.post("{php echo $this->createWebUrl('shop_order', array('op' => 'edit'))}", {storeid : storeid, id : id, action : action, roomid : roomid}, function(data) {
				data = $.parseJSON(data);
				console.dir(data);
				if (data.message.errno == 0) {
					util.message(data.message.message, 'refresh', 'success');
				} else {
					util.message(data.message.message);
				}
			});
		});
	});

	function formcheck() {
		if ($("#action").val() == 'is_refund' || $("#action").val() == '+' || $("#action").val() == 'is_live' || $("#status").val() == 8) {
			if (!confirm("请确认客户已支付过订单再做此操作！")){
				return false;
			}
		}
	}

	$('.js-select-room').click(function() {
		room_item_id = $(this).data('id');
		$.post("{php echo $this->createWebUrl('shop_order', array('op' => 'assign_room', 'storeid' => $_GPC['storeid']))}", {room_item_id : room_item_id, id : id, roomid : roomid}, function(data) {
			data = $.parseJSON(data);
			console.dir(data);
			if (data.message.errno != 0) {
				util.message(data.message.message, '', 'error');
			} else {
				util.message('分配成功', location.href, 'success');
			}
			$('#room-modal').modal('hide');
		});
	});
	$(function() {
		$('.order_set_room').click(function() {
			var index = $('.room-input');
			var rooms = [];
			var option = null;
			for (var i = 0; i < index.length; i++) {
				option = index[i];
				if (option.checked) {
					rooms.push(option.value);
				}
			}
			if (rooms.length != num) {
				util.message('所选房间数量跟订单房间数量不一致');
			}
			$.post("{php echo $this->createWebUrl('shop_order', array('op' => 'assign_room', 'storeid' => $_GPC['storeid']))}", {rooms : rooms, id : id, roomid : roomid}, function(data) {
				data = $.parseJSON(data);
				console.dir(data);
				if (data.message.errno != 0) {
					util.message(data.message.message, '', 'error');
				} else {
					util.message('分配成功', location.href, 'success');
				}
				$('#room-modal').modal('hide');
			});
		});
	});
</script>
{template 'common/footer'}